package com.b.Receive;

import com.b.dao.OrderMapper;
import com.b.domain.Order;
import com.b.repository.OrderRepository;
import jakarta.annotation.Resource;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


/**
 * @Description
 * @Author jdj
 * @Date 2025/7/25
 */
@Service
@Transactional
public class OrderReceive {
    @Resource
    private OrderMapper orderMapper;
    @Resource
    private OrderRepository orderRepository;

    @RabbitListener(queues = "order")
    @Transactional
    public void process(Order order) {
        System.out.println("order class: " + order.getClass());
        System.out.println("接收到消息：" + order);
        orderMapper.insert(order);
        orderRepository.save(order);
        System.out.println("保存成功");
    }
}
